package service

import (
	"context"
	"jk-time/webook/comment/domain"
	"jk-time/webook/comment/repository"
	"jk-time/webook/pkg/logger"
)

type CommentService interface {
	// GetCommentList Comment的id为0 获取一级评论
	// 按照 ID 倒序排序
	GetCommentList(ctx context.Context, biz string, bizId, minID, limit int64) ([]domain.Comment, error)
	// DeleteComment 删除评论，删除本评论何其子评论
	DeleteComment(ctx context.Context, id int64) error
	// CreateComment 创建评论
	CreateComment(ctx context.Context, comment domain.Comment) error
	GetMoreReplies(ctx context.Context, rid int64, maxID int64, limit int64) ([]domain.Comment, error)
}
type commentService struct {
	repo repository.CommentRepository
	l    logger.Logger
}

func NewCommentService(repo repository.CommentRepository, l logger.Logger) CommentService {
	return &commentService{repo: repo, l: l}
}

func (w *commentService) GetCommentList(ctx context.Context, biz string, bizId, minID,
	limit int64) ([]domain.Comment, error) {
	return w.repo.FindByBiz(ctx, biz, bizId, minID, limit)
}
func (w *commentService) DeleteComment(ctx context.Context, id int64) error {
	return w.repo.DeleteComment(ctx, domain.Comment{Id: id})
}
func (w *commentService) CreateComment(ctx context.Context, comment domain.Comment) error {
	return w.repo.CreateComment(ctx, comment)
}
func (w *commentService) GetMoreReplies(ctx context.Context, rid int64, maxID int64,
	limit int64) ([]domain.Comment, error) {
	return w.repo.GetMoreReplies(ctx, rid, int(maxID), int(limit))
}
